const fib = n => {
  if (n == 0) return 0
  if (n == 1) return 1
  let p = 0, q = 0, res = 1
  for (let i = 2; i <= n; i++) {
    p = q;
    q = res;
    res = p + q
    console.log(p, q);
  }
  return res
}

console.log(fib(4));